package com.mths.client.util;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.mths.client.widget.MessageBox;

public abstract class AsyncCall<T> implements AsyncCallback<T> {

	public AsyncCall() {
		// show spinner
		PageUtil.spinnerManager.showSpinner();
	}

	@Override
	public final void onSuccess(T result) {
		// hide spinner
		PageUtil.spinnerManager.hideSpinner();
		successCall(result);
	}

	@Override
	public final void onFailure(Throwable caught) {
		// hide spinner
		PageUtil.spinnerManager.hideSpinner();
		failCall(caught);
	}

	public abstract void successCall(T result);

	public void failCall(Throwable caught) {
		new MessageBox("İşlem sırasında bir hata ile karşılaşıldı. Lütfen Tekrar deneyiniz.");
	}
}
